<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../../common/taglibs.jsp"%>
<%@include file="../common/header_easyui.jsp" %>
<script language="javascript">
    $(document).ready(function () {
        jQuery("#docAttachmentsGrid").jqGrid({
            url:'${ctx}/document/getAttachments.do?docId=${param.docId}',
            datatype: "json",
//            colNames:["ID","文件名称","文件原始名称","上传时间","备注","操作"],
            colNames:["ID","文件名称","上传时间","备注","操作"],
            colModel:[
                {name:'id',index:'id',width:80,align:"center",sortable:false, hidden:true},
//                {name:'name',index:'name',width:80,align:"center",sortable:false},
                {name:'orginName',index:'orginName',width:80,align:"center",sortable:false},
                {name:'uploadDate',index:'uploadDate',width:80,align:"center",sortable:false},
                {name:'remark',index:'remark',width:80,align:"center",sortable:false},
                {name:'operation',index:'Id',width:80,align:"center",sortable:false}
            ],
            rowNum:10,
            autowidth :true, // 宽度自适应父窗口宽度
            mtype:"POST", // POST GET
            prmNames:{rows:"pageSize", sort:"orderBy", order:"order"}, // 设置翻页、排序参数
            rowList:[10,20,30,50],
            pager: '#pageDocAttachmentsGrid',
            jsonReader: { repeatitems : false },
            shrinkToFit: true,
//            caption: "文档附件列表",
//            multiselect: true,
            rownumbers: true,
            height: 200,
            gridComplete:function(){  //在此事件中循环为每一行添加修改和删除链接
                var ids=jQuery("#docAttachmentsGrid").jqGrid('getDataIDs');
                for(var i=0; i<ids.length; i++){
                    var id=ids[i];
                    var operation = "<a href='#' style='color:#f60' class='button' onclick='doDownload(\"${param.docId}\", " + id + ")'>下载</a>";
                    jQuery("#docAttachmentsGrid").jqGrid('setRowData', ids[i], { operation: operation});
                }
            }
        });

        jQuery("#docAttachmentsGrid").jqGrid('navGrid','#pageDocAttachmentsGrid',{edit:false,add:false,del:false,search:false});

        setGridWidth = function (width){
            jQuery("#docAttachmentsGrid").setGridWidth(width, true);
        };
    });

    function doDownload(docId, id) {
        <%--window.open('${ctx}/docAttachments/download.do?doc=' + docId + "&id=" + id);--%>
        $("#fileDownload").attr("src","${ctx}/docAttachments/download.do?doc=" + docId + "&id=" + id);
    }
</script>

<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
<div region="center" title="文档附件列表" style="width:100%; height:100%; background:#fafafa;overflow-x: hidden; overflow-y: auto;">
    <table id="docAttachmentsGrid"></table>
    <div id="pageDocAttachmentsGrid"></div>
    <div id="docAttachmentsWindow"></div>
    <iframe id="fileDownload" style="display: none"></iframe>
</div>
</body>
</html>